import {
  listLabelNode,
  pageProjectBaseInfo,
  saveProjectBaseInfo,
  deleteProjectBaseInfo
} from '../services/projectBaseInfo';

export default {
  namespace: 'projectBaseInfo',
  state: {
    currentPage: 1,
    pageSize: 10,
    total: 0,
    list: [],
    labelNodes: []
  },
  effects: {
    *listLabelNode(_, { put, call }) {
      const { data } = yield call(listLabelNode);
      yield put({
        type: 'listLabelNodeSuccess',
        payload: data,
      });
    },
    *pageProjectBaseInfo({ payload }, { put, call }) {
      const { data } = yield call(pageProjectBaseInfo, payload);
      yield put({
        type: 'pageProjectBaseInfoSuccess',
        payload: data,
      });
    },
    *saveProjectBaseInfo({ payload }, { put, call }) {
      const { code } = yield call(saveProjectBaseInfo, payload);
      if (code === 200) {
        yield put({
          type: 'global/refreshForPage',
        });
      }
    },
    *deleteProjectBaseInfo({payload},{put,call}) {
      const {code} = yield call(deleteProjectBaseInfo,payload);
      if(code === 200) {
        yield put({
          type: 'global/refreshForPage',
        })
      }
    }
  },
  reducers: {
    listLabelNodeSuccess(state, { payload }) {
      state.labelNodes = payload;
      return {
        ...state,
      };
    },
    pageProjectBaseInfoSuccess(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    }
  },
};
